package com.gexin.service.generalIntegralService;

import com.gexin.common.QrCodeKit;
import com.gexin.common.model.ApiResponse;
import com.gexin.common.utils.IdGenerateUtils;
import com.gexin.common.utils.QiNiuUtil;
import com.gexin.model.activity.AppStore;
import com.gexin.model.activity.AppStoreUrl;
import com.gexin.model.activity.GeneralIntegralSpeed;
import java.util.Date;
import java.util.List;


public class GeneralIntgralService {

    public static final GeneralIntegralSpeed generalIntegralSpeed = new GeneralIntegralSpeed();

    public List<GeneralIntegralSpeed> getGeneralIntegralSpeedList(){
        return GeneralIntegralSpeed.dao.findAll();
    }

    public Boolean deleteGeneralIntegralSpeedById(String id){
        return GeneralIntegralSpeed.dao.deleteById(id);
    }

    public ApiResponse writeQrCode(){
        QrCodeKit qrCodeKit = new QrCodeKit();
        List<AppStore> appStore = AppStore.dao.findAll();
        String s = listToString(appStore, ',');
        String appStoreStr = QiNiuUtil.upload(QrCodeKit.getQrCode(s), IdGenerateUtils.getId() + ".gif");
        AppStoreUrl appStoreUrl = new AppStoreUrl();
        long date = new Date().getTime();
        appStoreUrl.setId(System.currentTimeMillis()/1000+"");
        appStoreUrl.setAppStoreUrl(appStoreStr);
        appStoreUrl.setCreateTime(date);
        appStoreUrl.setUpdateTime(date);
        appStoreUrl.save();
        return new ApiResponse(true,"生成成功",0);
    }


    public static String listToString(List list, char separator) {
        return org.apache.commons.lang3.StringUtils.join(list.toArray(),separator);
    }
}
